﻿package plugin.instances.game
{
    import cmd.*;
    import com.core.*;
    import com.sh.game.util.*;
    import consts.*;
    import flash.events.*;
    import flash.utils.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import plugin.instances.*;
    import uiresource.instances.ui.*;
    import view.mornExtends.*;
    import vo.*;

    public class SBKGame extends SbkUI implements IInstance
    {
        private var lasttime2:int;
        private var zhanlinged:Boolean;
        private var _isinit:Boolean = false;
        private var _area:int = -1;
        private var _bei:int = 0;
        private static const activeid:int = 13;
        public static const sbkmapid:int = 1116;

        public function SBKGame()
        {
            return;
        }// end function

        override protected function initializeView() : void
        {
            super.initializeView();
            label_exp.text = "0";
            return;
        }// end function

        public function initShow(param1:Object, param2:Dictionary) : void
        {
            var _loc_3:Object = null;
            var _loc_4:int = 0;
            var _loc_5:Object = null;
            var _loc_6:Object = null;
            var _loc_7:Array = null;
            var _loc_8:Array = null;
            var _loc_9:int = 0;
            for (_loc_3 in param2)
            {
                
                this.updateShow(int(_loc_3), param2[_loc_3]);
            }
            label_name.text = param1.unionName;
            _loc_4 = param1.totalExp - int(label_exp.text);
            if (_loc_4 > 0)
            {
                WarningManager.show(18, ["经验", "+" + _loc_4, param1.totalExp]);
            }
            else if (_loc_4 < 0)
            {
                WarningManager.show(18, ["经验", _loc_4, param1.totalExp]);
            }
            label_exp.text = param1.totalExp;
            if (!this._isinit)
            {
                _loc_5 = ConfigDictionary.data.gameactive[activeid];
                _loc_6 = ConfigDictionary.data.item;
                _loc_7 = (_loc_5.items as String).split("#");
                _loc_8 = [];
                _loc_9 = 0;
                while (_loc_9 < _loc_7.length)
                {
                    
                    _loc_8.push(ItemObject.create(_loc_6[_loc_7[_loc_9]]));
                    _loc_9++;
                }
                list.renderHandler = new Handler(this.itemRender);
                list.array = _loc_8;
                this._isinit = true;
            }
            ModelProxy.change("zone", "SBKOwn", {unionid:param1.unionid, unionname:param1.unionName});
            this.updategetExp();
            ModelProxy.change("zone", "paoCheck", 2);
            return;
        }// end function

        public function updategetExp() : void
        {
            var _loc_1:* = UserData.getUserData("level");
            var _loc_2:int = 0;
            if (this._bei == 0)
            {
            }
            else if (this._bei == 1)
            {
                _loc_2 = 12000 * (int(_loc_1 / 10) - 5) * 6;
            }
            else if (this._bei == 2)
            {
                _loc_2 = 48000 * (int(_loc_1 / 10) - 5) * 6;
            }
            label_getexp.text = _loc_2 + "/分钟";
            return;
        }// end function

        public function initEvent() : void
        {
            shuoming.addEventListener(MouseEvent.ROLL_OVER, this.rollOVerHandler);
            shuoming.addEventListener(MouseEvent.ROLL_OUT, this.rollOutHandler);
            btn_tuichu.addEventListener(MouseEvent.CLICK, this.clickHandler);
            qizhi.clickHandler = new Handler(this.linkHandler);
            return;
        }// end function

        protected function clickHandler(event:MouseEvent) : void
        {
            PluginManager.instance.sendToServer("activity", CMDActivity.Trans, {x:123, y:115, tostageid:1035, free:1});
            return;
        }// end function

        protected function rollOVerHandler(event:MouseEvent) : void
        {
            ModelProxy.change("tips", "normal", "1.占领旗子就能占领沙巴克\n" + "2.活动结束时候占领旗子的帮会便是沙巴克霸主\n" + "3.每次开旗有30S冷却，此时间内旗子无法变更归属\n" + "4.旗杆附近的特效范围内是4倍经验区\n" + "5.活动结束时，位于沙巴克地图的玩家都有奖励");
            return;
        }// end function

        protected function rollOutHandler(event:MouseEvent) : void
        {
            ModelProxy.change("tips", "state", "close");
            return;
        }// end function

        private function itemRender(param1:Component, param2:int) : void
        {
            if (param2 < list.length)
            {
                (param1 as FlashItem).data = param1.dataSource;
            }
            return;
        }// end function

        public function updateShow(param1:int, param2:Object) : void
        {
            switch(param1)
            {
                case InstancesPublic.TIMECHECKER:
                {
                    label_time.text = TimeDataFormatUtil.getLeftTime(int(param2));
                    break;
                }
                case InstancesPublic.SBKAREA:
                {
                    if (this._area != int(param2))
                    {
                        this._area = int(param2);
                        label_double.text = this.getquad(this._area);
                    }
                    break;
                }
                case InstancesPublic.SBKGETEXPUPDATE:
                {
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function getquad(param1:int) : String
        {
            var _loc_2:String = "";
            this._bei = param1;
            this.updategetExp();
            switch(param1)
            {
                case 0:
                {
                    _loc_2 = "无经验";
                    break;
                }
                case 1:
                {
                    _loc_2 = "1倍区 ";
                    break;
                }
                case 2:
                {
                    _loc_2 = "4倍区 ";
                    break;
                }
                default:
                {
                    break;
                    break;
                }
            }
            return _loc_2;
        }// end function

        public function destroyShow(param1:Dictionary) : void
        {
            ModelProxy.change("zone", "paoCheck", -2);
            return;
        }// end function

        private function linkHandler() : void
        {
            ModelProxy.change("zone", "autoMove", {x:108, y:120, tostageid:Constant.SBKMapID, onhorse:true});
            return;
        }// end function

        public function removeEvent() : void
        {
            return;
        }// end function

    }
}
